<?php
if (!isset($_SESSION['login']) or !isset($_SESSION['senha'])) {
    header('location:/index.html');
 }
if($_SESSION['permissao'] === '1'){
         header('location: index.php');
       }
	 if (!isset($_SESSION['login']) or !isset($_SESSION['senha'])) {
 	header('location:/index.html');
 }
if (isset($_GET['alert']) && !empty($_GET['alert'])) {
    $alert =$_GET['alert'];
    echo "<script type='text/javascript'>alert('$alert');</script>";
  }
  
  $sql = "SELECT * FROM requisicao WHERE dt_baixa IS NULL AND matricula_fun_baixa IS NULL";
  $result = mysql_query($sql) or die(mysql_error());
  
  
?>
<html>
    <head>
        <script type="text/javascript">
            function fecharequisicao(cod){
                var con = confirm("Deseja realmente fechar esta requisição?");
                if(con){
                    window.location.href="index.php?page=requisicao/fecharequisicao.php&cod="+cod;
                }
            }

            function paint (id) {
        
        for (var i = 0; i < id; i++) {
            if (i % 2 == 0) {
                document.getElementById(i).style.backgroundColor='#E6F9F7';
            }else{
                document.getElementById(i).style.backgroundColor='#BED6F4';
            }
        }
    }
        </script>
    </head>
    <body>
        <div class="flist">
            <table class="tabela">
                <tr>
                     <th colspan="6"> Lista de Requisições</th>
                </tr>
                <tr>
                    <?php $i = 0; ?>
                    <th>Código</th>
                    <th>Nº Ferramenta</th>
                    <th>Mat Funcionário</td>
                    <th>Data</th>
                    <th>Mat. Atendente</th>
                    <th>Fechar Requisição</th>
                </tr>
                <?php while ($array = mysql_fetch_array($result)):?>
                <tr id="<?php echo $i; ?>">
                    <td><?php $cod = $array['cod_requisicao']; echo $cod; ?></td>
                    <td><?php echo $array['nu_ferramenta'];?></td>
                    <td><?php echo $array['matricula_func'];?></td>
                    <td><?php echo $array['dt_requisicao'];?></td>
                    <td><?php echo $array['matricula_fun_requisicao'];?></td>
                    <td><a href="index.php?page=requisicao/fecharequisicao.php&cod=<?php echo $cod;?>" >Fechar</a></td>
                </tr>
                <?php $i++; ?>
                <?php endwhile;?>
            </table>
            <script type="text/javascript">
                var i = '<?php echo $i; ?>'; 
                paint(i);
            </script>
        </div>
    </body>
</html>
